package com.hxx.yingda;

import com.hxx.danji.MQConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 1、应答模式的生产者
 * ①、
 * ②
 */
public class ProducerAck {


	//队列
	private static final String QUEUE_NAME = "hxx-test_queue";

	public static void main(String[] args) throws IOException, TimeoutException, TimeoutException {
		// 1.获取连接
		Connection newConnection = MQConnectionUtils.newConnection();
		// 2.创建通道
		Channel channel = newConnection.createChannel();

		/**
		 * 	3.创建队列声明
		 *
		 * 	参数1、队列名称
		 * 	参数2 是否持久化
		 */
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);

		for (int i = 0; i < 10; i++) {
			//消息
			String msg = "test_hxx-110" +i;
			System.out.println("应答模式生产者投递消息:" + msg );
			// 4.发送消息
			channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
		}
		channel.close();
		newConnection.close();
	}

}